package com.paradogs.framework.core.netty.clients.master;

import com.paradogs.framework.core.msg.ByteData;
import com.paradogs.framework.core.netty.clients.PRAbClientMsgHandler;
import com.paradogs.framework.core.netty.server.ServerProperties;
import com.paradogs.framework.core.utils.MsgUtils;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author: yumi
 * @date: 2023/11/4  15:52
 * @Description: TODO
 */
@Slf4j
@Component
@ChannelHandler.Sharable
public class PRMasterClientMsgHandler extends PRAbClientMsgHandler<ByteData> {

    @Autowired
    private ServerProperties serverProperties;

    public PRMasterClientMsgHandler() {
        super("master");
    }

    @Override
    protected void processMsg(ByteData msg) throws Exception {
        MsgUtils.adapterHandle(msg);
    }

    /**
     * 连接建立事件
     * @param ctx
     * @throws Exception
     */
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        super.channelActive(ctx);
        // 向中心注册自身信息
        MsgUtils.send("master|_master.init", serverProperties, ctx.channel());
    }

}
